package com.atguigu.lease.common.interceptor;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import java.util.Objects;

@Component
@Slf4j
public class GlobalInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        if (!(Objects.equals(request.getRemoteAddr(), "127.0.0.1") || Objects.equals(request.getRemoteAddr(), "192.168.13.235")|| Objects.equals(request.getRemoteAddr(), "0:0:0:0:0:0:0:1"))) {
            log.info(request.getRemoteAddr());
            response.sendRedirect("/not/allow");
            return false;
        }
        log.info(request.getRemoteAddr());
        return true;
    }

}
